<%--
  Created by IntelliJ IDEA.
  User: RuoLi
  Date: 2022/12/6
  Time: 19:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/base.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/iconfont.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/reg.css">
    <script TYPE="text/javascript" src="<%=request.getContextPath()%>/js/jquery.js"></script>
<%--    <script TYPE="text/javascript" src="<%=request.getContextPath()%>/js/agree.js"></script>--%>
<%--    <script type="text/javascript" src="<%=request.getContextPath()%>/js/index.js"></script>--%>
</head>
<body>
<div id="ajax-hook"></div>
<div class="wrap">
    <div class="wpn">
        <div class="form-data pos">
            <a href=""><img src="<%=request.getContextPath()%>/img/logo.png" class="head-logo"></a>
            <div class="change-login">
                <p class="account_number on">账号登录</p>
            </div>
            <div class="form1">
                <p class="p-input pos">
                    <label for="num">UID</label>
                    <input type="text" id="num">
                </p>
                <p class="p-input pos">
                    <label for="pass">请输入密码</label>
                    <input type="password" id="pass" autocomplete="new-password">
                </p>
            </div>
            <div class="r-forget cl">
                <a href="register.jsp" class="z">账号注册</a>
                <a href="forgetPassword.jsp" class="y">忘记密码</a>
            </div>
            <button class="lang-btn log-btn">登录</button>
        </div>
    </div>
</div>
</body>
<script>
    $(".log-btn").click(function () {
        if ($("#num").val().length<5||$("#pass").val().length<4){
            alert("账号密码长度不符合规范")
            $("#num").val("")
            $("#pass").val("")
        }else {
            $.ajax({
                type:"post",
                url:"User/UserLogin",
                data:{
                    userAccount:$("#num").val(),
                    userPassword:$("#pass").val()
                },
                success:function (data) {
                    if (data==0){
                        alert("账号或密码错误");
                    }
                    if (data==1) {
                        window.location.href = "user/main.jsp";
                    }else if(data==2){
                        window.location.href = "user/main.jsp";
                    } else if (data==3){
                        window.location.href = "admin/main_admin.jsp";
                    }
                },
                error:function () {
                    alert("登录失败")
                }
            })
        }
    });
    $(".icon-ok-sign").click(function(){
        verify = $(this).hasClass('boxcol') ? 0 : 1;
        $(this).toggleClass('boxcol');
        ob = $('input[name=agree]');
        ob.val(ob.val()==0?1:0);
        ob.val(ob.val() !== verify ? verify : ob.val());

        ob.val() == 0 ? $('#errormsg').removeClass('hide').addClass('show') : $('#errormsg').removeClass('show').addClass('hide');
    });
    //输入框输入时模拟placeholder效果
    var oInput = $(".form-data input");
    oInput.focus(function () {
        $(this).siblings("label").hide();
    });
    oInput.blur(function () {
        if($(this).val()==""){
            $(this).siblings("label").show();
        }
    });
    // 输入框内容变化按钮颜色发生变化
    oInput.keyup(function () {
        if($(this).val()!="jquery.js"){
            $(".log-btn").removeClass("off")
        }else{
            $(".log-btn").addClass("off")
        }
    });
</script>
</html>
